package com.zd.lwsp.controller;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import com.zd.lwsp.vo.AppInfoProcessVo;
import com.zd.lwsq.domain.ApplicationInfo;
import com.zd.lwsq.service.ApplicationInfoService;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.zd.lwsp.domain.AppInfoProcess;
import com.zd.lwsp.service.AppInfoProcessService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 离疆申请流程状态对象Controller
 * 
 * @author fxiao
 * @date 2020-08-08
 */
@Controller
@RequestMapping("/sp/process")
public class AppInfoProcessController extends BaseController
{
    private String prefix = "sp/process";

    @Autowired
    private AppInfoProcessService appInfoProcessService;

    @Autowired
    private ApplicationInfoService applicationInfoService;

    @RequiresPermissions("sp:process:view")
    @GetMapping()
    public String process()
    {
        return prefix + "/process";
    }

    /**
     * 查询离疆申请流程状态对象列表
     */
    @RequiresPermissions("sp:process:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppInfoProcess appInfoProcess)
    {
        startPage();
//        List<AppInfoProcess> list = appInfoProcessService.selectAppInfoProcessList(appInfoProcess);
        List<AppInfoProcessVo> list = appInfoProcessService.selectAppInfoProcessListForRole(appInfoProcess);
        return getDataTable(list);
    }

    /**
     * 导出离疆申请流程状态对象列表
     */
    @RequiresPermissions("sp:process:export")
    @Log(title = "离疆申请流程状态对象", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppInfoProcess appInfoProcess)
    {
        List<AppInfoProcess> list = appInfoProcessService.selectAppInfoProcessList(appInfoProcess);
        ExcelUtil<AppInfoProcess> util = new ExcelUtil<AppInfoProcess>(AppInfoProcess.class);
        return util.exportExcel(list, "process");
    }

    /**
     * 新增离疆申请流程状态对象
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存离疆申请流程状态对象
     */
    @RequiresPermissions("sp:process:add")
    @Log(title = "离疆申请流程状态对象", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppInfoProcess appInfoProcess)
    {
        return toAjax(appInfoProcessService.insertAppInfoProcess(appInfoProcess));
    }

    /**
     * 修改离疆申请流程状态对象
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) throws InvocationTargetException, IllegalAccessException {
        AppInfoProcess appInfoProcess = appInfoProcessService.selectAppInfoProcessById(id);
        AppInfoProcessVo appInfoProcessVo=new AppInfoProcessVo();
        BeanUtils.copyProperties(appInfoProcessVo,appInfoProcess);
        ApplicationInfo applicationInfo = applicationInfoService.selectApplicationInfoById(appInfoProcessVo.getYwdxId());
        appInfoProcessVo.setApplicationInfo(applicationInfo);
        mmap.put("appInfoProcess", appInfoProcessVo);
        return prefix + "/edit";
    }

    /**
     * 修改保存离疆申请流程状态对象
     */
    @RequiresPermissions("sp:process:edit")
    @Log(title = "离疆申请流程状态对象", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppInfoProcess appInfoProcess)
    {
        return toAjax(appInfoProcessService.updateAppInfoProcess(appInfoProcess));
    }

    /**
     * 删除离疆申请流程状态对象
     */
    @RequiresPermissions("sp:process:remove")
    @Log(title = "离疆申请流程状态对象", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appInfoProcessService.deleteAppInfoProcessByIds(ids));
    }
}
